## Figure A9: Clustering of Closing Dates by Day of Month and Neighborhood Income

## install.packages(c("tidyverse"))
## library(tidyverse)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("dta.RData")

clustering_days_of_month_inc = dta %>%
  filter(!is.na(close_day_of_month)) %>%
  filter(!is.na(inc_third)) %>%
  mutate(n = 1,
         close_day_of_month = factor(close_day_of_month)) %>%
  group_by(inc_third, close_day_of_month) %>%
  summarise(n_requests_closed = sum(n, na.rm = TRUE)) %>%
  ggplot(aes(x = factor(close_day_of_month), y = n_requests_closed, fill = factor(inc_third))) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_x_discrete(labels = c("1", "", "", "", "", "", "", "",
                              "", "", "", "", "", "", "15", "",
                              "", "", "", "", "", "", "", "",
                              "", "", "", "", "", "30", "")) +
  scale_fill_brewer(name = "Per Capita Income Tercile", palette = "Blues", labels = c("Top", "Middle", "Bottom")) +
  labs(x = "Day of Month",
       y = "# of Requests Closed") +
  theme_classic() +
  theme(legend.position = "bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))